from fastapi import APIRouter, Depends
from schemas import food
from typing import Any,List
from crud.crud_food import crudfood
from deps.deps import get_session
# 子路由 针对指定接口
router=APIRouter (prefix="/food",tags=["食物模块接口"])

@router.get("/all",response_model= List[food.FoodSchema])
def get_all(session=Depends(get_session)):
    return crudfood.getAll(db= session)
@router.get("/one/{id}",response_model= food.FoodSchema)
def get_byid(id:Any,session=Depends(get_session)):
    return crudfood.getById(db=session,id=id)

@router.post("/save",response_model= food.FoodSchema)
def save(foodschema:food.FoodSchema,session=Depends(get_session)):
    return crudfood.save(db=session,foodSchema=foodschema)